package com.yiren.dbaa.module.practice_set.map.view.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.yiren.dbaa.R;

import java.util.List;

/**
 * Describe 新增道路标识适配器
 */
public class AddRoadMarkAdapter extends BaseAdapter {

    private Context context;
    private int type;  //1:可选的标识 2：选择的标识
    private List<Integer> roadMarkList;
    private OnRoadMarkActionListener listener;

    public AddRoadMarkAdapter(Context context, int type, List<Integer> roadMarkList, OnRoadMarkActionListener listener) {
        this.context = context;
        this.type = type;
        this.roadMarkList = roadMarkList;
        this.listener = listener;
    }

    @Override
    public int getCount() {
        return roadMarkList.size();
    }

    @Override
    public Object getItem(int position) {
        return roadMarkList.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(final int position, View convertView, ViewGroup parent) {
        ViewHolder mHolder;
        if (convertView == null) {
            convertView = LayoutInflater.from(context).inflate(R.layout.item_add_road_mark, parent, false);
            mHolder = new ViewHolder(convertView);
            convertView.setTag(mHolder);
        } else {
            mHolder = (ViewHolder) convertView.getTag();
        }
        int roadType = roadMarkList.get(position);
        switch (roadType) {
            case 10:
                mHolder.ivRoadMark.setImageResource(type == 1 ? R.mipmap.mark_no_zx : R.mipmap.mark_select_zx);
                mHolder.tvRoadMark.setText("直行");
                break;
            case 11:
                mHolder.ivRoadMark.setImageResource(type == 1 ? R.mipmap.mark_no_yz : R.mipmap.mark_select_yz);
                mHolder.tvRoadMark.setText("右转");
                break;
            case 12:
                mHolder.ivRoadMark.setImageResource(type == 1 ? R.mipmap.mark_no_zz : R.mipmap.mark_select_zz);
                mHolder.tvRoadMark.setText("左转");
                break;
            case 13:
                mHolder.ivRoadMark.setImageResource(type == 1 ? R.mipmap.mark_no_dt : R.mipmap.mark_select_dt);
                mHolder.tvRoadMark.setText("掉头");
                break;
            case 14:
                mHolder.ivRoadMark.setImageResource(type == 1 ? R.mipmap.mark_no_zxzz : R.mipmap.mark_select_zxzz);
                mHolder.tvRoadMark.setText("直行左转");
                break;
            case 15:
                mHolder.ivRoadMark.setImageResource(type == 1 ? R.mipmap.mark_no_zxyz : R.mipmap.mark_select_zxyz);
                mHolder.tvRoadMark.setText("直行右转");
                break;
            case 16:
                mHolder.ivRoadMark.setImageResource(type == 1 ? R.mipmap.mark_no_zxdt : R.mipmap.mark_select_zxdt);
                mHolder.tvRoadMark.setText("直行掉头");
                break;
            case 17:
                mHolder.ivRoadMark.setImageResource(type == 1 ? R.mipmap.mark_no_zzdt : R.mipmap.mark_select_zzdt);
                mHolder.tvRoadMark.setText("左转掉头");
                break;
            case 18:
                mHolder.ivRoadMark.setImageResource(type == 1 ? R.mipmap.mark_no_zxzzdt : R.mipmap.mark_select_zxzzdt);
                mHolder.tvRoadMark.setText("直行左转");
                break;
            case 21:
                mHolder.ivRoadMark.setImageResource(type == 1 ? R.mipmap.mark_no_zyz : R.mipmap.mark_select_zyz);
                mHolder.tvRoadMark.setText("左右转");
                break;
        }
        if (type == 1) {
            mHolder.ivMarkAction.setImageResource(R.mipmap.projet_edit_right_tpe_button_highlight);
            mHolder.tvRoadMark.setTextColor(context.getResources().getColor(R.color.content));
        } else {
            mHolder.ivMarkAction.setImageResource(R.mipmap.middle_tpe_button_normal);
            mHolder.tvRoadMark.setTextColor(context.getResources().getColor(R.color.main_gray));
        }
        convertView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                listener.onRoadMarkAction(type, position);
            }
        });
        return convertView;
    }

    class ViewHolder {
        ImageView ivRoadMark;
        TextView tvRoadMark;
        ImageView ivMarkAction;

        public ViewHolder(View itemView) {
            ivRoadMark = (ImageView) itemView.findViewById(R.id.iv_road_mark);
            tvRoadMark = (TextView) itemView.findViewById(R.id.tv_road_mark);
            ivMarkAction = (ImageView) itemView.findViewById(R.id.iv_mark_action);
        }
    }

    public interface OnRoadMarkActionListener {
        void onRoadMarkAction(int type, int position);
    }
}
